//
//  HistorylotterTableViewCell.m
//  BCW
//
//  Created by Mac on 16/3/30.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "HistoryCell.h"
#import "HistoryModel.h"
#import "HistoryOneCellModel.h"
#import "HistoryLotteryViewController.h"
static int a1;
static int a2;
static int a3;
static int a4;
static int a5;

static NSString *b1;
static NSString *b2;
static NSString *b3;
static NSString *b4;
static NSString *b5;

static NSMutableArray *arrOne;

@interface HistoryCell()

@property (strong, nonatomic) IBOutlet UILabel *phase_txt;
@property (strong, nonatomic) IBOutlet UILabel *time_txt;
@property (strong, nonatomic) IBOutlet UIView *cellview;
@property (strong, nonatomic) IBOutlet UILabel *one_number;
@property (strong, nonatomic) IBOutlet UILabel *two_number;
@property (strong, nonatomic) IBOutlet UILabel *three_number;
@property (strong, nonatomic) IBOutlet UILabel *four_number;
@property (strong, nonatomic) IBOutlet UILabel *five_number;


@property (strong, nonatomic) NSString *numberTwo;
@property (strong, nonatomic) NSString *numberOne;
@property (strong, nonatomic) NSString *numberTwo3;
@property (strong, nonatomic) NSString *numberTwo4;
@property (strong, nonatomic) NSString *numberTwo5;
@end

@implementation HistoryCell


- (void)awakeFromNib {
  
    [super awakeFromNib];
}
- (void)setViewColor:(UIColor *)viewColor
{
    _viewColor = viewColor;
    _cellview.backgroundColor = viewColor;
}
//2016-03-29 23:55:43  20160329120
- (void)setHistoryonecellmodel:(HistoryOneCellModel *)historyonecellmodel
{
    _historyonecellmodel = historyonecellmodel;
    
    NSString *strExpect = historyonecellmodel.expect;
    NSString *expectstr =[strExpect substringWithRange:NSMakeRange(8,3)];
    _phase_txt.text = [NSString stringWithFormat:@"%@期",expectstr];
    NSString *strTime = historyonecellmodel.opentime;
//    self.time_txt.text =[strTime substringWithRange:NSMakeRange(10,6)];
    if (strTime.length > 16) {
        self.time_txt.text =[strTime substringWithRange:NSMakeRange(10,6)];
    }
    else{
        self.time_txt.text = strTime;
    }
    
    
    arrOne=[NSMutableArray array];
    UIColor *redColor=[UIColor redColor];
    UIColor *purpleColor=[UIColor purpleColor];
    UIColor *brownColor=[UIColor brownColor];
    UIColor *blueColor=[UIColor blueColor];
    UIColor *greenColor=[UIColor greenColor];
    
    
    NSString *strNumber = historyonecellmodel.opencode;
    
    a1= [[strNumber substringWithRange:NSMakeRange(0,1)] intValue];
    a2= [[strNumber substringWithRange:NSMakeRange(2,1)] intValue];
    a3= [[strNumber substringWithRange:NSMakeRange(4,1)] intValue];
    a4= [[strNumber substringWithRange:NSMakeRange(6,1)] intValue];
    a5= [[strNumber substringWithRange:NSMakeRange(8,1)] intValue];
    b1=[strNumber substringWithRange:NSMakeRange(0,1)];
    b2=[strNumber substringWithRange:NSMakeRange(2,1)];
    b3=[strNumber substringWithRange:NSMakeRange(4,1)];
    b4=[strNumber substringWithRange:NSMakeRange(6,1)];
    b5=[strNumber substringWithRange:NSMakeRange(8,1)];
    
    for (int i=0; i<5; i++) {
        NSMutableDictionary *dic=[NSMutableDictionary dictionary];
        
        if (i==0) {
            [dic setObject:redColor forKey:b1];
            [arrOne addObject:dic];
        }
        if (i==1) {
            [dic setObject:purpleColor forKey:b2];
            [arrOne addObject:dic];
        }
        if (i==2) {
            [dic setObject:brownColor forKey:b3];
            [arrOne addObject:dic];
        }
        if (i==3) {
            [dic setObject:blueColor forKey:b4];
            [arrOne addObject:dic];
        }
        if (i==4) {
            [dic setObject:greenColor forKey:b5];
            [arrOne addObject:dic];
        }
        
    }
    
    self.numberOne =[strNumber substringWithRange:NSMakeRange(0,1)];
    _one_number.textColor = [UIColor redColor];
    self.one_number.text = _numberOne ;
    self.two_number.text = [strNumber substringWithRange:NSMakeRange(2,1)];
    _two_number.textColor = [UIColor purpleColor];
    self.three_number.text = [strNumber substringWithRange:NSMakeRange(4,1)];
    _three_number.textColor = [UIColor brownColor];
    self.four_number.text = [strNumber substringWithRange:NSMakeRange(6,1)];
    _four_number.textColor = [UIColor blueColor];
    self.five_number.text = [strNumber substringWithRange:NSMakeRange(8,1)];
    _five_number.textColor = [UIColor greenColor];
    
    
}

- (void)setHistorylotterymodel:(HistoryModel *)historylotterymodel
{
    _historylotterymodel = historylotterymodel;
    
    NSString *strExpect = historylotterymodel.expect;
    NSString *expectstr =[strExpect substringWithRange:NSMakeRange(8,3)];
    _phase_txt.text = [NSString stringWithFormat:@"%@期",expectstr];
    NSString *strTime = historylotterymodel.opentime;
    if (strTime.length > 16) {
        self.time_txt.text =[strTime substringWithRange:NSMakeRange(10,6)];
    }
    else{
        self.time_txt.text = @"12:00";
    }
    
    NSString *strNumber = historylotterymodel.opencode;
    NSMutableArray *arr=[NSMutableArray array];
    
    
    
    //1
    _numberOne =[strNumber substringWithRange:NSMakeRange(0,1)];
    [arr addObject:_numberOne];
    _one_number.text = _numberOne;
    
    //2.
    _numberTwo =[strNumber substringWithRange:NSMakeRange(2,1)];
    [arr addObject:_numberTwo];
    _two_number.text =[strNumber substringWithRange:NSMakeRange(2,1)];
    
    //3
    _numberTwo3 =[strNumber substringWithRange:NSMakeRange(4,1)];
    [arr addObject:_numberTwo3];
    _three_number.text =[strNumber substringWithRange:NSMakeRange(4,1)];
    
    //4
    _numberTwo4 =[strNumber substringWithRange:NSMakeRange(6,1)];
    [arr addObject:_numberTwo4];
    _four_number.text =[strNumber substringWithRange:NSMakeRange(6,1)];
    
    //5
    _numberTwo5 =[strNumber substringWithRange:NSMakeRange(8,1)];
    [arr addObject:_numberTwo5];
    _five_number.text =[strNumber substringWithRange:NSMakeRange(8,1)];
    
    NSMutableArray *arr2=[NSMutableArray array];
    for (int i=0; i<5 ;i++) {
        NSString *str=arr[i];
        
        int a=[str intValue];
        NSMutableDictionary *dic=[NSMutableDictionary dictionary];
        
        if (a==a1 || a==a2 || a==a3 || a==a4 || a==a5) {
            [dic setObject:str forKey:[NSString stringWithFormat:@"%d",i]];
            [arr2 addObject:dic];
        }else{
            [dic setObject:@"" forKey:[NSString stringWithFormat:@"%d",i]];
            [arr2 addObject:dic];
        }
        
    }
    
    for (int i=0 ;i<5; i++) {
        
        NSMutableDictionary  *dic2;
        NSMutableDictionary  *dic1;
        
        if(arr2.count>i)
            dic2=arr2[i];
        
        for (int n=0; n<5; n++) {
            dic1=arrOne[n];
            
            NSString *str=[dic2 objectForKey:[NSString stringWithFormat:@"%d",i]];
            if (![str  isEqual: @""]) {
                if (_one_number.tag == i+1) {
                    
                    for (int m=0; m<10; m++) {
                        UIColor *col=[dic1 objectForKey:[NSString stringWithFormat:@"%d",m]];
                        if (col) {
                            if (m ==[str intValue])
                                _one_number.textColor =col; ;
                        }
                    }
                }
                
                if (_two_number.tag==i+1) {
                    for (int m=0; m<10; m++) {
                        UIColor *col=[dic1 objectForKey:[NSString stringWithFormat:@"%d",m]];
                        if (col) {
                            if (m ==[str intValue])
                                _two_number.textColor =col; ;
                        }
                    }
                }
                if (_three_number.tag==i+1) {
                    for (int m=0; m<10; m++) {
                        UIColor *col=[dic1 objectForKey:[NSString stringWithFormat:@"%d",m]];
                        if (col) {
                            if (m ==[str intValue])
                                _three_number.textColor =col; ;
                        }
                    }
                }
                if (_four_number.tag==i+1) {
                    for (int m=0; m<10; m++) {
                        UIColor *col=[dic1 objectForKey:[NSString stringWithFormat:@"%d",m]];
                        if (col) {
                            if (m ==[str intValue])
                                _four_number.textColor =col; ;
                        }
                    }
                }
                if (_five_number.tag==i+1) {
                    for (int m=0; m<10; m++) {
                        UIColor *col=[dic1 objectForKey:[NSString stringWithFormat:@"%d",m]];
                        if (col) {
                            if (m ==[str intValue]) {
                                _five_number.textColor =col; ;
                            }
                        }
                    }
                }
            }
            
        }
        
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
